package zzzhc.image.recognize.nn;

import org.joone.engine.KohonenSynapse;
import org.joone.engine.Layer;
import org.joone.engine.LinearLayer;
import org.joone.io.MemoryOutputSynapse;
import org.joone.net.NeuralNet;

public abstract class AbstractSOM extends NNBase {
	protected Layer coreLayer;

	protected abstract Layer createCoreLayer(NNInput nnInput);

	protected void doSetNNInput() {
		inputLayer.removeAllInputs();
		input = nnInput.createInputSynapse();
		inputLayer.addInputSynapse(input);
		inputLayer.setRows(nnInput.getFetureNum());

		if (output != null) {
			coreLayer.removeOutputSynapse(output);
		}
		output = new MemoryOutputSynapse();
		coreLayer.addOutputSynapse(output);

		doSubSetNNInput();
	}

	protected abstract void doSubSetNNInput();

	protected void buildNeuralNet() {

		LinearLayer linearLayer = new LinearLayer();

		KohonenSynapse kohonenSynapse = new KohonenSynapse();

		coreLayer = createCoreLayer(nnInput);

		linearLayer.addOutputSynapse(kohonenSynapse);
		coreLayer.addInputSynapse(kohonenSynapse);

		neuralNet = new NeuralNet();
		neuralNet.addLayer(linearLayer);
		neuralNet.addLayer(coreLayer);

		inputLayer = linearLayer;
		outputLayer = coreLayer;
	}

}